package com.lxblyw.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.lxblyw.entity.IdeaComment;
import com.lxblyw.util.DBHelp;
import com.lxblyw.util.RowMapper;

public class IdeaCommentDao {
	
	private DBHelp<IdeaComment> dbhelp = new DBHelp<IdeaComment>();
	
	private class IdeaCommentRowMapper implements RowMapper<IdeaComment> {

		public IdeaComment mapperRow(ResultSet rs) throws SQLException {
			IdeaComment comment = new IdeaComment();
			comment.setId(rs.getString("id"));
			comment.setContent(rs.getString("content"));
			comment.setCreatetime(rs.getString("createtime"));
			comment.setEmployeeid(rs.getString("employeeid"));
			comment.setIdeaid(rs.getString("ideaid"));
			return comment;
		}
	}
	
	public List<IdeaComment> findByIdeaId(String id) {
		String sql = "select * from t_ideacomment where ideaid = ? order by createtime desc";
		return dbhelp.executeQueryForList(sql, new IdeaCommentRowMapper(), id);
	}

	public void save(IdeaComment comment) {
		String sql = "insert into t_ideacomment(id,content,createtime,ideaid,employeeid) values(?,?,?,?,?)";
		dbhelp.executeSQL(sql, comment.getId(),comment.getContent(),comment.getCreatetime(),comment.getIdeaid(),comment.getEmployeeid());
	}

	public void delete(String id) {
		String sql = "delete from t_ideacomment where id = ?";
		dbhelp.executeSQL(sql, id);
	}
	
}
